<template>
  <div>
    <span class="time"> {{ currentDate }}</span>
  </div>
</template>

<script>
export default {
  name: 'ManageTime',

  data() {
    return { currentDate: '' };
  },

  mounted() {
    this.getCurrentDate();
    this.timer = setInterval(this.getCurrentDate, 1200);
  },

  methods: {
    getCurrentDate() {
      var that = this;
      var now = new Date();
      // 获取完整的年份
      var year = now.getFullYear();
      // 范围0~11， 跟中国的月份相差1
      var month = now.getMonth() + 1;
      // getDate表示获取当前时间对应的月份中的天数
      var days = now.getDate();
      // 表示获取星期数 ,西方国家的星期数是 0~6,0代表的是周日,其他的分别是周一到周六
      var dayOfWeek = now.getDay();
      var week = ' ';
      switch (dayOfWeek) {
        case 0:
          week = '星期日';
          break;
        case 1:
          week = '星期一';
          break;
        case 2:
          week = '星期二';
          break;
        case 3:
          week = '星期三';
          break;
        case 4:
          week = '星期四';
          break;
        case 5:
          week = '星期五';
          break;
        case 6:
          week = '星期六';
          break;
        default:
          week = ' ';
          break;
      }
      that.currentDate = year + '年' + month + '月' + days + '日' + ' ' + week;
    },
  },
};
</script>

<style lang="less" scoped>
.time {
  color: rgb(248, 247, 247);
  text-shadow: 3px 1px 6px #2e492e;
}
</style>
